home *** CD-ROM | disk | FTP | other *** search
- Path: cs.mu.OZ.AU!bounce-back
- From: boukanov@hadron.fi.uib.no (Igor Boukanov)
- Newsgroups: comp.std.c++
- Subject: Re: Placement delete suggestion
- Date: 30 Mar 96 05:29:24 GMT
- Organization: Fysisk institutt, Universitetet i Bergen
- Approved: fjh@cs.mu.oz.au
- Message-ID: <4jgeld$e3s@ugress.uib.no>
- References: <4j4ec5$d41@fsgi01.fnal.gov> <9603261124.AA22276@lts.sel.alcatel.de> <4jboij$4t3@mulga.cs.mu.OZ.AU> <4jc296$h0t@news.BelWue.DE>
- NNTP-Posting-Host: munta.cs.mu.oz.au
- Keywords: delete placement
- X-Original-Date: 29 Mar 1996 10:39:41 GMT
- X-Newsreader: TIN [version 1.2 PL2]
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBFAgUBMVzG4eEDnX0m9pzZAQE7ZAF9GZMajuB8MX+r9l6lnmWrGbwckHW8HTSZ
- D+QHn3msW85G10b0at4hN0GJhlMjBj7i
- =fxMl
- Originator: fjh@munta.cs.mu.OZ.AU
-
- Dietmar Kuehl (kuehl@uzwil.informatik.uni-konstanz.de) wrote:
-
- > OTOH, as Tim Hollebeek observed in a thread in comp.lang.c++.moderated
- > (Placement new and arrays), the usefulness of placement array new is
- > limited anyway: There is no portable way to figure out how much
- > "allocation overhead" there will be and thus it is impossible to
- > predict how much memory has to be set aside for a placement array new.
-
- But there is a way to way to figure out how much is "allocation overhead"!
- Here an example:
-
- void* operator new[](size_t size, size_t& retSize) {
- retSize = size;
- return NULL;
- }
-
- So you can call write something like this:
-
- class T { ... };
- ...
- size_t size;
- new(size) T[100];
- T* p = new(alloca(size)) T[100]; // allocate memory from stack
- ...
- for (int i = 99; i >= 0; i--) { p[i].~T(); }
- // instead of placement delete ...
-
- --
- With best regards, Igor Boukanov
- igor.boukanov@fi.uib.no http://www.fi.uib.no/~boukanov
- ---
- [ comp.std.c++ is moderated. To submit articles: try just posting with ]
- [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
- [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
- [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
- [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
-